package fatboy.hypeerweb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;



/**
 * 
 * @author James
 *
 *Designed to test NodePointer, its children and PointerList
 *
 */
public class TestNodePointer {

	@Test
	public void TestEdgePointer(){
		Node temp = new Node("Im an Edge", NodeType.SURFACE_NODE, new NodeAddress(0));
		NodePointer testptr1 = new EdgePointer(temp);
		
		
		assertTrue( testptr1.isSameType(new EdgePointer(temp)) );
		assertFalse( testptr1.isSameType(new SurrogatePointer(temp)));
		assertEquals( testptr1.getNode(), temp );
		
	}
	
	@Test
	public void TestSurrogatePointer(){
		Node temp = new Node("Im an Edge", NodeType.SURFACE_NODE, new NodeAddress(0));
		//temp.setAddress(new NodeAddress());
		NodePointer testptr2 = new SurrogatePointer(temp);
		
		
		assertTrue( testptr2.isSameType(new SurrogatePointer(temp)) );
		assertFalse( testptr2.isSameType(new EdgePointer(temp)));
		assertEquals( testptr2.getNode(), temp );
	}
	
	@Test
	public void TestPointerList(){
		List<NodePointer> tempList = new PointerList();
		int i = 0;
		Node temp1 = new Node(i, NodeType.SURFACE_NODE, new NodeAddress(i++));
		NodePointer testptr1 = new EdgePointer(temp1);
		
		assertTrue(tempList.add(testptr1));
		assertTrue(tempList.size()==1);
		assertTrue(tempList.get(0).equals(testptr1));
		
		Node temp2 = new Node(i, NodeType.SURFACE_NODE, new NodeAddress(i++));
		
		NodePointer testptr2 = new EdgePointer(temp2);
		
		assertTrue(tempList.add(testptr2));
		assertFalse(tempList.add(testptr2));
		
		Node temp3 = new Node("Bad First", NodeType.SURFACE_NODE, new NodeAddress(2));
		
		NodePointer badptr1 = new SurrogatePointer(temp3);	
		
		assertFalse(tempList.add(badptr1));
		
		Node temp4 = new Node(i, NodeType.SURFACE_NODE, new NodeAddress(i++));
		
		NodePointer testptr3 = new EdgePointer(temp4);
		
		assertTrue(tempList.add(testptr3));
		assertEquals(tempList.get(0),testptr3);
		
		tempList.clear();
		NodePointer revptr1 = new SurrogatePointer(temp1);
		tempList.add(revptr1);
		NodePointer revptr2 = new SurrogatePointer(temp2);
		tempList.add(revptr2);
		NodePointer revptr3 = new SurrogatePointer(temp4);	
		tempList.add(revptr3);
		
		assertEquals(tempList.get(0), revptr1);
		assertEquals(tempList.get(tempList.size()-1) ,revptr3);
	}
}
